<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'traceMatrix.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<script type="text/javascript" language="javascript" src="js/jquery-1.7.1.js"></script>
		<script>
			$(function(){
			$('td.cell').css('cursor','pointer');
				$('td.cell').dblclick(function(){
					var currObj=$(this);
					value=$(this).children('span.value').text();
					fromId=$(this).children('input.fromId').attr('value');
					toId=$(this).children('input.toId').attr('value');
					fromtable=$(this).children('input.fromtable').attr('value');
					totable=$(this).children('input.totable').attr('value');
					if(fromId != '-1' & toId != '-1' ){
						if(value=='X'){
							if(window.confirm('delete this trace?')){
			                 	 	url='deleteTrace?fromId='+fromId+'&'+'toId='+toId+'&'+'fromtable='+fromtable+'&'+'totable='+totable;
			                 	 	$.ajax({
										  url: url,
										  cache:false,
										  success: function(returnData, textStatus) {
										  		currObj.children('span.value').text('');
											},
										    error: function(xhr, textStatus, errorThrown) {
										      	alert('fail');
										    }
										});
			             	 }else{
			                	 // do nothing
			             	}
						}else{
							if(window.confirm('add this trace?')){
			                 	 	url='addTrace?fromId='+fromId+'&'+'toId='+toId+'&'+'fromtable='+fromtable+'&'+'totable='+totable;
			                 	 	alert(fromtable+" and "+totable);
			                 	 	$.ajax({
										  url: url,
										  cache:false,
										  success: function(returnData, textStatus) {
										  		currObj.children('span.value').text('X');
											},
										    error: function(xhr, textStatus, errorThrown) {
										      	alert('fail');
										    }
										});
			             	 }else{
			                	 // do nothing
			             	}
						}
					}
				});
			});
		</script>
	</head>

	<body>
		<table  cellspacing='10' cellpadding='10' align='center'>
			<s:iterator value="matrix">
				<tr>
					<s:iterator value="top" id="inner">
						<td class='cell'>
							<span class='value'><s:property value="#inner.value"/></span>
							<input class='fromId' type='text' value='<s:property value="#inner.fromId" />' style='display: none'/>
							<input class='toId' type='text' value='<s:property value="#inner.toId" />' style='display: none'/>
							<input class='fromtable' type='text' value='<s:property value="#inner.fromtable" />' style='display: none'/>
							<input class='totable' type='text' value='<s:property value="#inner.totable" />' style='display: none'/>
						</td>
					</s:iterator>
				</tr>
			</s:iterator>
		</table>
	</body>
</html>


